package com.jinduplan.planmanager.mvp.presenter

import com.cxz.kotlin.baselibs.ext.ss
import com.cxz.kotlin.baselibs.mvp.BasePresenter
import com.cxz.kotlin.baselibs.utils.LogUtil
import com.fphoenixcorneae.util.toast.ToastUtil
import com.jinduplan.planmanager.mvp.contract.LoginRegisterContract
import com.jinduplan.planmanager.mvp.model.LoginRegisterModel
import okhttp3.RequestBody

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class LoginRegisterPresenter : BasePresenter<LoginRegisterContract.Model, LoginRegisterContract.View>(), LoginRegisterContract.Presenter {

    override fun createModel(): LoginRegisterContract.Model = LoginRegisterModel()

    override fun register(username: String, password: String, code: String) {
        mModel?.register(username, password,code)?.ss(mModel, mView, onSuccess = {
            mView?.registerSuccess(it.data!!)
        })
    }

    override fun changePsw(username: String, password: String, code: String) {
        mModel?.changePsw(username, password,code)?.ss(mModel, mView, onSuccess = {
            mView?.changePswSuccess(it.data!!)
        })
    }


    override fun login(username: String, password: String) {
        mModel?.login(username,password)?.ss(mModel,mView,onSuccess = {
            mView?.loginSuccess(it.data!!)

        },onError = {

        })

    }



    override fun smsSend(phone: RequestBody) {
        mModel?.smsSend(phone)?.ss(mModel, mView, onSuccess = {
            mView?.getCodeSuccess()
        }, onError = {
            mView?.getCodeFail()
            LogUtil.d("errorCode->${it.code}")
            ToastUtil.show(it.msg)
        })
    }

    override fun loginWithSms(username: String, sms: String) {
    }


}